# demo03.py    JSON
import json
adict = {"name": "tom", "age": 20}
# dict -> json     json.dumps(dict)
data = json.dumps(adict)  # 将字典转换为json格式
print("json:", data)  # {"name": "tom", "age": 20}
print(type(data))  # <class 'str'>

# json -> dict     json.loads(json)
str01 = '{"name": "zhangsan", "age": 18}'
data = json.loads(str01)
print(data)  # {'name': 'zhangsan', 'age': 18}
print(type(data))  # <class 'dict'>
print(data["name"], data["age"])  # zhangsan 18


